package com.youi.web;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.youi.exception.BusinessException;
import com.youi.manage.HttpRequestManage;
import com.youi.manage.HttpSessionManage;
import com.youi.common.DelStatus;
import com.youi.common.SessionKey;
import com.youi.service.GroupleaderService;
import com.youi.service.LeaderprofitdetailService;
import com.youi.entity.Groupleader;
import com.youi.entity.Leaderprofitdetail;
import com.youi.entity.User;
import com.youi.common.Common;
import com.youi.util.CommonInfoUtil;
import com.youi.util.DateUtil;
import com.youi.util.JedisUtils;
import com.youi.util.JsonUtil;
import com.youi.util.ObjectUtil;
import com.youi.util.Page;

/**
* 团长佣金流水明细控制层
* @author Administrator
*/
@Controller
public class LeaderprofitdetailController  extends HttpRequestManage{

		@Autowired
		private LeaderprofitdetailService leaderprofitdetailService;
		@Autowired
		private GroupleaderService groupleaderService;

		
		/**
		 * M-24
		 * 查询团长佣金流水明细
		*/
		@ResponseBody
		@RequestMapping("userGetInfo/leader/getLeaderprofitdetail")
		public String getLeaderprofitdetail(ModelMap modelMap,HttpServletRequest request) throws BusinessException,ParseException{
			User user=(User) HttpSessionManage.getAttribute(request, SessionKey.USER);		
			Integer pageIndex=optInteger("pageIndex",request,1);
			Integer pageNum=optInteger("pageNum",request,10);
			Integer type=optInteger("type",request);
			String des=optString("des",request,Common.DESC);
			String pms=optString("pms",request);
			Date start=optDate("start",request,"yyyy-MM-dd HH:mm:ss");
			Date end=optDate("end",request,"yyyy-MM-dd HH:mm:ss");
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("leaderId", user.getLeaderId());
			if (type!=null) {
				prams.put(Common.TYPE, type);
			}
			Map<String, Object> sortPram=new HashMap<String, Object>();
			sortPram.put(Common.ID,des);
			Map<String, Object> searchPram=null;
			if (pms!=null) {
				searchPram=new HashMap<String, Object>();
			}
			Map<String, Object> startTime=null;
			if(start!=null){
				startTime=new HashMap<String, Object>();
				startTime.put(Common.GMTCREATED,start);
			}
			Map<String, Object> endTime=null;
			if(end!=null){
				endTime=new HashMap<String, Object>();
				endTime.put(Common.GMTCREATED,end);
			}
			List<Leaderprofitdetail> leaderprofitdetailList=leaderprofitdetailService.getByParamsList(prams, searchPram,sortPram,  (pageIndex-1)*pageNum, pageNum, startTime, endTime);
			if (leaderprofitdetailList==null||leaderprofitdetailList.size()==0) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			Integer pageCount=leaderprofitdetailService.getCountByParamss(prams, searchPram, startTime, endTime);
			modelMap.put(CommonInfoUtil.PAGECOUNT, Page.getCount(pageCount, pageNum));//pageCount  总页数
			modelMap.put(CommonInfoUtil.PAGEINDEX, pageIndex);			//pageIndex     查询页数
			modelMap.put(CommonInfoUtil.ALLCOUINT,pageCount);
			modelMap.put(CommonInfoUtil.DATA, leaderprofitdetailList);		//jsonObjectList json对象集合
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",modelMap);
		}
}
